package com.yupi.springbootinit.autocommit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum QuestionEnum {
    sql(KBEnum.KB900231002, "form_biz_id多语言引发问题，乱码，报错。"),
    dmlError(KBEnum.KB900231002, "dml执行报错"),
    batchEditButNotPermissionsRefactoring(KBEnum.KB900231003, "批量编辑后没有进行权限重构"),
    browserPageError(KBEnum.KB900231002, "浏览框分页问题"),
    refNoFlush02(KBEnum.KB900231002, "老布局报错(引用了分表改造方法，而没有修改的类)KB900231002解决部分", Arrays.asList(AutoCommit.formatFilePath("\\src\\weaver\\formmode\\webservices\\ModeDataServiceImpl.java"))),
    jsp(KBEnum.KB900231003, "jsp相关问题"),
    refNoFlush03(KBEnum.KB900231003, "老布局报错(引用了分表改造方法，而没有修改的类)KB900231003解决部分"),
    refNoFlush2402(KBEnum.KB900240102, "解决了普通模式下，前台页面打开无反应的问题(引用了分表改造方法，而没有修改的类)",Arrays.asList(AutoCommit.formatFilePath("\\formmode\\view\\AddFormMode.jsp"))),

    vformTransMethod(KBEnum.KB900240102,"VSQL视图的查询，配置显示转换，添加显示转换条件不生效");


    /**
     * 解决此问题的版本
     */
    private KBEnum disposeKb;
    /**
     * 描述
     */
    private String desc;

    /**
     * 关联的文件
     */
    private List<String> refFile;

    QuestionEnum(KBEnum disposeKb, String desc) {
        this.disposeKb = disposeKb;
        this.desc = desc;
    }

    QuestionEnum(KBEnum disposeKb, String desc, List<String> refFile) {
        this.disposeKb = disposeKb;
        this.desc = desc;
        this.refFile = refFile;
    }

    public KBEnum getDisposeKb() {
        return disposeKb;
    }

    public String getDesc() {
        return desc;
    }

    public List<String> getRefFile() {
        return refFile;
    }

    static {
        jsp.refFile = Arrays.asList(
                AutoCommit.formatFilePath("\\docs\\docs\\DocDspExt.jsp"),
                AutoCommit.formatFilePath("\\formmode\\data\\ModeDataOperation.jsp"),
                AutoCommit.formatFilePath("\\formmode\\interfaces\\ModeDataBatchImport.jsp"),
                AutoCommit.formatFilePath("\\formmode\\setup\\ExcleFieldOperation.jsp"),
                AutoCommit.formatFilePath("\\formmode\\setup\\ModeImportConditionIframe.jsp"),
                AutoCommit.formatFilePath("\\formmode\\setup\\batchmodifyfeildvalueOperation.jsp"),
                AutoCommit.formatFilePath("\\formmode\\setup\\customSearchActionForFront.jsp"),
                AutoCommit.formatFilePath("\\formmode\\view\\AddFormModeIframe.jsp"),
                AutoCommit.formatFilePath("\\formmode\\view\\ModeLogViewDetail.jsp"),
                AutoCommit.formatFilePath("\\formmode\\view\\ModeLogViewIframe.jsp"),
                AutoCommit.formatFilePath("\\mobilemode\\formbasebrowserview.jsp"),
                AutoCommit.formatFilePath("\\workflow\\request\\ViewRequest.jsp")
        );

        dmlError.refFile = Arrays.asList(AutoCommit.formatFilePath("\\src\\weaver\\formmode\\interfaces\\dmlaction\\commands\\actions\\DMLAction.java"));

        batchEditButNotPermissionsRefactoring.refFile = Arrays.asList(AutoCommit.formatFilePath("\\src\\com\\api\\cube\\service\\CubeSearchEditService.java"));

        browserPageError.refFile = Arrays.asList(AutoCommit.formatFilePath("\\src\\com\\api\\browser\\service\\impl\\FormmodeBrowserService.java"));

        refNoFlush03.refFile = Arrays.asList(
                AutoCommit.formatFilePath("\\src\\com\\engine\\cube\\cmd\\restfulinterface\\DeleteModeDataByPK.java"),
                AutoCommit.formatFilePath("\\src\\com\\engine\\edcreport\\biz\\loader\\action\\ModeSaveAction.java"),
                AutoCommit.formatFilePath("\\src\\com\\api\\wbi\\bus\\util\\ModeAfterSaveAction.java")
        );

        vformTransMethod.refFile = Arrays.asList(AutoCommit.formatFilePath("\\src\\com\\api\\cube\\util\\CubeSearchTransMethod.java"));


        sql.refFile = new ArrayList<>();
    }

    /**
     * 获取当前kb需要处理的所有文件列表
     * @param kb
     * @return
     */
    public static List<String> getAllFilePathWithKb(KBEnum kb) {
        List<String> collect = Arrays.stream(QuestionEnum.values()).filter(s -> s.disposeKb.getKbNumber() > kb.getKbNumber()).distinct().flatMap(s -> s.refFile.stream()).collect(Collectors.toList());
        return collect;
    }

    /**
     * 获取当前kb所有未解决的问题列表
     * @param kbEnum
     * @return
     */
    public static List<QuestionEnum> getAllQuestWithKb(KBEnum kbEnum) {
        return Arrays.stream(QuestionEnum.values()).filter(s -> s.disposeKb.getKbNumber() > kbEnum.getKbNumber()).collect(Collectors.toList());
    }

    public static void main(String[] args) {
        List<String> allwithKb = getAllFilePathWithKb(KBEnum.KB900240101);
        for (int i = 0; i < allwithKb.size(); i++) {
            System.out.println(i+allwithKb.get(i));
        }

        System.out.println("--------------------------");
        List<QuestionEnum> allwithKb2 = getAllQuestWithKb(KBEnum.KB900240101);
        for (int i = 0; i < allwithKb2.size(); i++) {
            System.out.println(i+allwithKb2.get(i).desc);
        }

    }
}
